package cn.diancan.action.api;

import com.opensymphony.xwork2.ModelDriven;

import cn.diancan.action.BaseAction;
import cn.diancan.exception.OutMsgException;
import cn.diancan.model.ShopCustomer;
import cn.diancan.vo.ShopCustomerApiActionVo;
import cn.diancan.vo.ShopCustomerVo;

public class ShopCustomerAction extends BaseAction implements ModelDriven<ShopCustomerApiActionVo>{
    
    private ShopCustomerApiActionVo requestVo = new ShopCustomerApiActionVo();

    /**
     * 
     */
    private static final long serialVersionUID = 6920935157163522366L;
    
    
    public String checkCustomerByOrder(){
	try {
	    ShopCustomerVo customer =  shopCustomerService.findByOutOrderNumber(requestVo.getPurchaseSaleOutOrderNumber());
	    return jsonFormat(customer);
	}  catch (Exception e) {
	    return jsonError(e);
	}
    }
    
    //查询 (使用手机号码 -或会员编号)
    // 
    
    public String checkCustomer(){ 
	try {
	    ShopCustomerVo vo = shopCustomerService.findByPhoneNum(requestVo.getCustomerPhoneNum());
	    return jsonFormat(vo);
	}  catch (Exception e) { 
	    return jsonError(e);
	}
    }
    
    //添加
    public String addCustomer(){
	try {
	    ShopCustomerVo vo = shopCustomerService.saveVipShopCustomer(requestVo.getCustomerName(),requestVo.getCustomerPhoneNum(),requestVo.getCustomerSex()
	    	,requestVo.getCustomerBrithDay(),requestVo.getCustomerReMarks());
	    return jsonFormat(vo);
	}  catch (Exception e) { 
	    return jsonError(e);
	}
    }
    
    //修改
    public String modifyCustomer(){
	try {
	    ShopCustomerVo vo = shopCustomerService.updateVipShopCustomer(requestVo.getShopCustomerId(),requestVo.getCustomerName(), requestVo.getCustomerSex()
	    	,requestVo.getCustomerBrithDay(),requestVo.getCustomerReMarks());
	    return jsonFormat(vo);
	}  catch (Exception e) { 
	    return jsonError(e);
	}
    }
    
    

    @Override
    public ShopCustomerApiActionVo getModel() { 
	return requestVo;
    }
    
    
    
    
    

}
